package com.isasa.android.bluetoothpractice.sound;

import android.media.AudioManager;
import android.media.SoundPool;

import com.isasa.android.bluetoothpractice.R;
import com.isasa.android.bluetoothpractice.base.BaseApplication;

/**
 * Created by Python on 2017/5/20.
 */

public class GesturePlay {
    private static volatile GesturePlay player;
    private SoundPool soundPool;
    private int soundId[];
    private  GesturePlay(){}
    public static GesturePlay getPlayer(){
        if(player==null){
            synchronized (GesturePlay.class){
                if(player==null){
                    player = new GesturePlay();
                }
            }
        }
        return player;
    }


    @Deprecated
    public void init(){
        if(soundPool!=null){
            soundPool.release();
        }
        soundPool = null;
        soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC,0);
        soundId = new int[20];
//        for(int i=0;i<soundId.length;i++){
//            //TODO maybe need .OGG file
//            soundId[i]=soundPool.load(BaseConst.BasePath+File.separator+(i+1)+".ogg",1);
//        }
        soundId[1]=soundPool.load(BaseApplication.getContext(),R.raw.aa,1);
        soundId[4]=soundPool.load(BaseApplication.getContext(),R.raw.dd,1);
        soundId[6]=soundPool.load(BaseApplication.getContext(),R.raw.ff,1);
        soundId[10]=soundPool.load(BaseApplication.getContext(),R.raw.sword_dp,1);
        soundId[11]=soundPool.load(BaseApplication.getContext(),R.raw.sword_left,1);
        soundId[12]=soundPool.load(BaseApplication.getContext(),R.raw.sword_right,1);
    }
    public void play(int index){
        soundPool.play(soundId[index],1,1,1,0,1);
    }
    public void release(){
        if(soundPool!=null){
            soundPool.release();
        }
        soundPool = null;
    }
}
